package com.geostar.mina.handler;

import java.util.List;

import org.apache.mina.core.service.IoHandlerAdapter;  
import org.apache.mina.core.session.IoSession;  

import com.geostar.mina.core.ProcessExe;
import com.geostar.mina.model.ProcessModel;
  
public class MinaServerHanlder extends IoHandlerAdapter {  
    private int count = 0;  
    
    @Override 
    public void sessionCreated(IoSession session) {  
        System.out.println("与客户端连接");  
    }  
  
    @Override  
    public void sessionOpened(IoSession session) throws Exception {  
        count++;  
        System.out.println("第 " + count + " 个 client 登陆！address： : "  
                + session.getRemoteAddress());  
    }  
  
	@Override  
    public void sessionClosed(IoSession session) throws Exception {  
        session.close(true);  
        System.out.println("Server closed!");  
    }  
  
	@SuppressWarnings("unchecked")
	@Override  
    public void messageReceived(IoSession session, Object message)  
            throws Exception {  
      List<ProcessModel> pmList = (List<ProcessModel>) message ;
      // 查找指定进程状态
      pmList = ProcessExe.process(pmList);
      session.write(pmList);
    }  
}  